# -*- coding: utf-8 -*-
# @Time    : 2024/11/29 上午11:02
# @Author  : wjx
# @Email   : kanxinxin@163.com
# @File    : menu.py
# @Software: PyCharm
from appium.webdriver.common.appiumby import AppiumBy as By
from pages.base_page import BasePage


class RedactMenuPage(BasePage):
    # 定位器
    menu_title_locator = (By.ID, 'com.xiachufang:id/et_recipe_name')  # 菜谱表题
    ingredient_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/et_ing")')  # 食材
    amount_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/et_amount")')  # 用量
    add_steps_description_locator = (
        By.XPATH, '//android.widget.EditText[@resource-id="com.xiachufang:id/et_step_desc"]')  # 添加步骤说明
    senior_settings_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                       '"com.xiachufang:id/dtv_advanced_set")')  # 高级设置按钮
    # 仅自己可见
    only_myself_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/tb_private")')
    finish_locator = (By.XPATH, '//android.widget.TextView[@resource-id="com.xiachufang:id/tv_right"]')     # 完成
    # 发布
    publish_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/tv_publish")')
    # 发布成功
    publish_success_locator = (By.XPATH,'//*[@text = "发布成功"]')
    close_redact_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/img_container")')
    do_not_save_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("不保存")')

    def input_menu_title(self, title):
        """
        点击添加菜谱表题，并输入标题
        :param title:
        :return: None
        """
        title_element = self.find_element(self.menu_title_locator)
        title_element.click()
        title_element.send_keys(title)

    def input_ingredient(self, ingredient):
        """
        点击食材并输入食材
        :param ingredient:
        :return: None
        """
        ingredient_element = self.find_element(self.ingredient_locator)
        ingredient_element.click()
        ingredient_element.send_keys(ingredient)

    def input_amount(self, amount):
        """
        点击用量并输入
        点击用量并输入
        :param amount:
        :return: None
        """
        amount_element = self.find_element(self.amount_locator)
        amount_element.click()
        amount_element.send_keys(amount)

    def input_steps_description(self, steps_description):
        """
        点击添加步骤说明，并输入说明
        :param steps_description:
        :return: None
        """
        el = self.find_element(self.add_steps_description_locator)
        el.click()
        el.send_keys(steps_description)

    def click_senior_settings(self):
        """
        点击高级设置
        :return: None
        """
        self.find_element(self.senior_settings_locator).click()

    def click_only_myself(self):
        """
        点击仅自己可见的按钮
        :return: None
        """
        self.find_element(self.only_myself_locator).click()

    def click_finish(self):
        """
        点击完成
        :return: None
        """
        self.find_element(self.finish_locator).click()

    def click_publish(self):
        """
        点击发布这个菜谱
        :return:None
        """
        self.find_element(self.publish_locator).click()

    def publish_success(self):
        """
        发布成功提示语
        :return: 返回发布成功提示语
        """
        tips_ele = self.find_element(self.publish_success_locator)
        return tips_ele.text

    def click_close_redact(self):
        """
        点击左上角的×
        :return: None
        """
        self.find_element(self.close_redact_locator).click()

    def click_do_not_save(self):
        """
        点击不保存
        :return: None
        """
        self.find_element(self.do_not_save_locator).click()

